package com.cn.shiro_jwt_redis.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.cn.shiro_jwt_redis.comm.model.ResultData;
import com.cn.shiro_jwt_redis.comm.utils.RedisUtil;
import com.cn.shiro_jwt_redis.mapper.MenuMapper;
import com.cn.shiro_jwt_redis.pojo.Menu;
import com.cn.shiro_jwt_redis.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 张坤鹏
 * @Date: 2021/08/04/10:21
 * @Description:
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;
    @Override
    public ResultData getLoginMenuTree(Integer loginId) {
        List<Menu> list=menuMapper.getRoot(loginId);
        if (list.size()>0){
            for (Menu menu:list) {
                List<Menu> list1=menuMapper.getChildren(loginId,menu.getMenuId());
                menu.setMenuChildren(list1);
            }
            return ResultData.ok().data(list);
        }
        return ResultData.error();
    }
}
